package com.qezhhnjy.mall.member.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.member.MemberCollectSpu;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.member.service.MemberCollectSpuService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 会员收藏的商品 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "会员收藏的商品接口")
@Slf4j
@RequestMapping("/member-collect-spu")
public class MemberCollectSpuController {
    @Resource
    private MemberCollectSpuService memberCollectSpuService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取会员收藏的商品信息")
    public BaseResult<MemberCollectSpu> get(Long id) {
        MemberCollectSpu memberCollectSpu = memberCollectSpuService.getById(id);
        return BaseResult.success(memberCollectSpu);
    }

    @PostMapping("/save")
    @Operation(summary = "新增会员收藏的商品信息")
    public BaseResult<MemberCollectSpu> save(@RequestBody MemberCollectSpu memberCollectSpu) {
        memberCollectSpuService.save(memberCollectSpu);
        return BaseResult.success(memberCollectSpu);
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员收藏的商品信息")
    public BaseResult<MemberCollectSpu> update(@RequestBody MemberCollectSpu memberCollectSpu) {
        memberCollectSpuService.updateById(memberCollectSpu);
        return BaseResult.success(memberCollectSpu);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取会员收藏的商品信息")
    public BaseResult<Page<MemberCollectSpu>> page(@RequestBody Page<MemberCollectSpu> page) {
        memberCollectSpuService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除会员收藏的商品信息")
    public BaseResult<Long> delete(Long id) {
        memberCollectSpuService.removeById(id);
        return BaseResult.success(id);
    }
}

